home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / Found / FWStream / Include / FWArOper.h < prev    next >
Encoding:
Text File  |  1996-08-16  |  5.0 KB  |  137 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWArOper.h
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef FWAROPER_H
  11. #define FWAROPER_H
  12.  
  13. #ifndef FWARDYNA_H
  14. #include "FWArDyna.h"
  15. #endif
  16.  
  17. #ifndef FWPRIDEB_H
  18. #include "FWPriDeb.h"
  19. #endif
  20.  
  21. //----------------------------------------------------------------------------------------
  22. // FW_SomCast
  23. //----------------------------------------------------------------------------------------
  24.  
  25. SOMObject* FW_SomCast(SOMObject *object, SOMClass *className);
  26.  
  27. //----------------------------------------------------------------------------------------
  28. // FW_READ_DYNAMIC_OBJECT
  29. //
  30. // Global function for reading from a readableStream. The type 'className'
  31. // must be a dynamic class or a compile-time error will occur.
  32. //----------------------------------------------------------------------------------------
  33.  
  34. // JEL:
  35. // I would like to be able to pass FW_TYPEID_FROM_TYPE(tType) into
  36. // FW_CPrivArchiver::CreateObject, and then use RTTI to enforce the requirement
  37. // that the object contained in the stream is a valid subtype of tType.
  38. // Unfortunately, native C++ RTTI doesn't give me a built-in way to do it
  39. // (I need a function that takes two typeids and returns true if one is a subtype
  40. // of the other, and dynamic_cast can't be used for this).
  41. // The ODF RTTI emulation has this capability, but we expect native RTTI will be used
  42. // by most developers.
  43.  
  44. template <class tType>
  45. inline void FW_ReadObject(FW_CReadableStream& stream, tType*& object)
  46. {
  47.     FW_CPrivArchiver::CreateObject(stream, (void *&)(object));
  48.     
  49. #ifndef FW_COMPILER_SUPPORTS_RTTI
  50.     // This is really a compile/link time check, it's not much help as a runtime check.
  51.     // All it does is verify that the class tType has both the FW_DECARE_CLASS
  52.     // and W_DEFINE_CLASS_Mx macros.  If FW_DECLARE_CLASS is missing, the line should
  53.     // result in a compile-time error.  If FW_DEFINE_CLASS_Mx is missing, it will result
  54.     // in a link-time error. (Because of a compiler bug, the MPW based compilers can not 
  55.     // handle this particular check -- so we disable it for them. [SFU] )
  56. #if !defined __SC__ && !defined __MRC__
  57.     FW_ASSERT(FW_PrivStaticGetClassInfo(object) != 0);
  58. #endif
  59. #endif
  60. }
  61.  
  62. #if 1
  63.     // The template function is a 
  64.     #define FW_READ_DYNAMIC_OBJECT(stream, object, className) \
  65.         FW_ReadObject(stream, *object)
  66. #else
  67.     #define FW_READ_DYNAMIC_OBJECT(stream, object, className) \
  68.         { \
  69.             className** _temp_ = object;    \
  70.             FW_CPrivArchiver::CreateObject(stream, (void *&)(*_temp_)); \
  71.             *(object) = FW_DYNAMIC_CAST(className, *_temp_); \
  72.         }
  73. #endif
  74.  
  75. //----------------------------------------------------------------------------------------
  76. // FW_WRITE_DYNAMIC_OBJECT
  77. //
  78. // Global function for writing to a writableStream. The type 'className' must
  79. // must be a dynamic class or a compile-time error will occur.
  80. //----------------------------------------------------------------------------------------
  81.  
  82. template <class tType>
  83. inline void FW_WriteObject(FW_CWritableStream& stream, const tType* object)
  84. {
  85.     const char* classString = object != NULL
  86.                         ? FW_CLASSNAME_FROM_POINTER(object) 
  87.                         : FW_CLASSNAME_FROM_TYPE(tType);
  88.     FW_CPrivArchiver::OutputObject(stream, object, classString);
  89. }
  90.  
  91. #if 1
  92.     #define FW_WRITE_DYNAMIC_OBJECT(stream, object, className) \
  93.         FW_WriteObject(stream, object)
  94. #else
  95.     #define FW_WRITE_DYNAMIC_OBJECT(stream, object, className) \
  96.         { \
  97.             const className* _temp_ = object;    \
  98.             const char* classString = _temp_ != NULL \
  99.                                 ? FW_CLASSNAME_FROM_POINTER(_temp_) \
  100.                                 : FW_CLASSNAME_FROM_TYPE(className); \
  101.             FW_CPrivArchiver::OutputObject(stream, _temp_, classString); \
  102.         }
  103. #endif
  104.  
  105. //----------------------------------------------------------------------------------------
  106. // FW_READ_DYNAMIC_SOM_OBJECT
  107. //
  108. // Global function for reading from a readableStream. The type 'className'
  109. // must be a dynamic class or a compile-time error will occur.
  110. //----------------------------------------------------------------------------------------
  111.  
  112. #define FW_READ_DYNAMIC_SOM_OBJECT(stream, object, className) \
  113.     { \
  114.         className** _temp_ = object;    \
  115.         FW_CPrivArchiver::CreateObject(stream, (void *&)(*_temp_)); \
  116.         *(object) = (className*)FW_SomCast(*_temp_,className##ClassData.classObject); \
  117.     }
  118.  
  119.  
  120. //----------------------------------------------------------------------------------------
  121. // FW_WRITE_DYNAMIC_SOM_OBJECT
  122. //
  123. // Global template function for writing to a writableStream. The type 'className' must
  124. // must be a dynamic class or a compile-time error will occur.
  125. //----------------------------------------------------------------------------------------
  126.  
  127. #define FW_WRITE_DYNAMIC_SOM_OBJECT(stream, object, className) \
  128.     { \
  129.         className* _temp_ = object;    \
  130.         if (_temp_ != NULL) \
  131.             FW_CPrivArchiver::OutputObject(stream, _temp_, _temp_->somGetClassName()); \
  132.         else \
  133.             FW_CPrivArchiver::OutputObject(stream, 0, #className); \
  134.     }
  135.  
  136. #endif
  137.